package org.six11.ss.client;

import java.util.Comparator;

import org.six11.util.Debug;

/**
 * 
 *
 * @author Gabe Johnson <johnsogg@cmu.edu>
 */
public class ScoreInfo {

  protected String playerName = "unknown player";
  protected int lifetimeScore = -1;
  protected int gameScore = -1;
  protected int roundScore = -1;
  
  public static Comparator<ScoreInfo> lifetimeComparator = new Comparator<ScoreInfo>() {
    public int compare(ScoreInfo o1, ScoreInfo o2) {
     int ret = 0;
     if (o1.getLifetimeScore() < o2.getLifetimeScore()) {
       ret = -1;
     } else if (o1.getLifetimeScore() > o2.getLifetimeScore()) {
       ret = 1;
     }
     return ret;
    }
  };
  
  public static Comparator<ScoreInfo> gameComparator = new Comparator<ScoreInfo>() {
    public int compare(ScoreInfo o1, ScoreInfo o2) {
     int ret = 0;
     if (o1.getGameScore() < o2.getGameScore()) {
       ret = -1;
     } else if (o1.getGameScore() > o2.getGameScore()) {
       ret = 1;
     }
     return ret;
    }
  };

  public static Comparator<ScoreInfo> roundComparator = new Comparator<ScoreInfo>() {
    public int compare(ScoreInfo o1, ScoreInfo o2) {
     int ret = 0;
     if (o1.getRoundScore() < o2.getRoundScore()) {
       ret = -1;
     } else if (o1.getRoundScore() > o2.getRoundScore()) {
       ret = 1;
     }
     return ret;
    }
  };
  
  public static Comparator<ScoreInfo> nameComparator = new Comparator<ScoreInfo>() {
    public int compare(ScoreInfo o1, ScoreInfo o2) {
     return o1.getPlayerName().compareTo(o2.getPlayerName());
    }
  };
  
  public String getPlayerName() {
    return playerName;
  }
  public void setPlayerName(String playerName) {
    this.playerName = playerName;
  }
  public int getLifetimeScore() {
    return lifetimeScore;
  }
  public void setLifetimeScore(int lifetimeScore) {
    this.lifetimeScore = lifetimeScore;
  }
  public int getGameScore() {
    return gameScore;
  }
  public void setGameScore(int gameScore) {
    this.gameScore = gameScore;
  }
  public int getRoundScore() {
    return roundScore;
  }
  public void setRoundScore(int roundScore) {
    this.roundScore = roundScore;
  }
  
  public String toString() {
    StringBuffer buf = new StringBuffer();
    buf.append("Score info for " + getPlayerName());
    if (getLifetimeScore() >= 0) {
      buf.append(" Lifetime: " + getLifetimeScore());
    }
    if (getGameScore() >= 0) {
      buf.append(" Game: " + getGameScore());
    }
    if (getRoundScore() >= 0) {
      buf.append(" Round: " + getRoundScore());
    }
    return buf.toString();
  }
  
  private static void bug(String what) {
    Debug.out("ScoreInfo", what);
  }
}
